require 'bzcommon'

include Bzflag
include BZCommon


class Announcer < Plugin

  def initialize()
  end

  
  def player_join(data)
  
    ids = bz_get_player_index_list
    ids.each do |id|
      bz_send_text_message(BZ_SERVER, id ,"Everybody say 'TI-DI-DI', #{data.callsign} has joined!")  
    end
  end
  
  def player_die(data)
    if !is_server_player(data.killer_id)
      killer = Player.new(data.killer_id)    
      if is_score_max(killer)
           game_end_function
      end             
    end
  end
  
  def game_end_function     
    winner = get_winner   
    ids = bz_get_player_index_list

    ids.each do |id|
      player = Player.new(id)
      bz_send_text_message(BZ_SERVER, player.player_id ,"#{winner.callsign} has won! Congratulations!")
     end
  end
  
  def game_end(data)
      game_end_function
  end
  

  def destructor()
  end

end

# new Announcer instance
announcer = Announcer.new()

# register Announcer plugin
announcer.register 